<?php
if(!empty($this->city)) { $this->headMeta()->setName('keywords',$this->translator->translator('property_front_page_list').' ('.$this->city.')');}
if(!empty($this->city)) { $this->headMeta()->setName('description',$this->translator->translator('property_front_page_list').' ('.$this->city.')'); }
if(!empty($this->city)) { $this->headTitle()->headTitle($this->translator->translator('property_front_page_list').' ('.$this->city.')','SET'); }

echo $this->headScript()->setFile($this->baseUrl().'/js/jquery/table-sorter/jquery.dataTables.js');
echo $this->headScript()->setFile($this->baseUrl().'/js/jquery/jtruncate/jquery.jtruncate.pack.js');
echo $this->headLink()->setStylesheet($this->baseUrl().'/css/jqueryCSS/table-sorter/pagination_table.css');

$business_type_db = new Property_Model_DbTable_BusinessType();
$state_db = new Property_Model_DbTable_State();
$area_db = new Property_Model_DbTable_Area();
$country_db = new Property_Model_DbTable_Country();
$review_helper = new Review_View_Helper_Review();
$maximum_stars_digit = $this->translator->translator('maximum_stars_digit');
// 1ist param options are : like, inline, plus_minus, horizontal, triangle
$vote = new Vote_Controller_Helper_ShowVoteButton('inline','hotels_page' );
$front_template = Zend_Registry::get('front_template');

$global_conf = Zend_Registry::get('global_conf');
$currency = new Zend_Currency($global_conf['default_locale']);

function property_truncate($phrase,$start_words, $max_words)
{
   $phrase_array = explode(' ',$phrase);
   if(count($phrase_array) > $max_words && $max_words > 0)
	  $phrase = implode(' ',array_slice($phrase_array, $start_words, $max_words)).'...';  
   return $phrase;
}
?>

<?php 
$allow_obj = new Property_View_Helper_Allow();
if (!$allow_obj->allowRule('view',null,null,$this->group_datas['role_id'])) : ?>
	<?php echo $this->translator->translator('Member_Access_deny_desc'); ?>
<?php else : 

$property_title_name = ($this->menu_info) ? $this->escape($this->menu_info['menu_name']) : $this->escape($this->businessTypeInfo['business_type']);
?>

<div class="mod">
    <div class="property-list-icon">
        <h1><?php echo $this->translator->translator('property_front_page_list').' ('.$this->city.')'; ?></h1>
    </div>
    
    <div class="social">
        <!-- AddThis Button BEGIN -->
        <div class="addthis_toolbox addthis_default_style">
        <a class="addthis_button_facebook_like" fb:like:layout="button_count"></a>
        <a class="addthis_button_tweet"></a>
        <a class="addthis_button_google_plusone" g:plusone:size="medium"></a>
        <a class="addthis_counter addthis_pill_style"></a>
        </div>
        <script type="text/javascript" src="http://s7.addthis.com/js/250/addthis_widget.js#pubid=xa-4e89660c7edb029a"></script>
        <!-- AddThis Button END -->
	</div>

	<div class="clear"></div>
	<table id="sortTable" width="100%" border="0" align="center" cellpadding="0" cellspacing="0" >
        <tbody>
          <?php
            foreach($this->view_datas as $entry)
            {
                $property_image_val_arr = explode(',',$entry['property_image']);
                $property_image_no = (empty($property_image_val_arr[0])) ? '0' : count($property_image_val_arr);
                $businessTypeInfo = $business_type_db->getBusinessTypeInfo($entry['property_type']);
                if($this->escape($entry['property_primary_image']))
                { 
                    $thumb_image = 'data/frontImages/property/property_image/'.$this->escape($entry['property_primary_image']); 
                }
                else
                { 
                    if($this->escape($entry['property_image']))
                    {
                        $thumb_image = 'data/frontImages/property/property_image/'.$this->escape($property_image_val_arr[0]); 
                    }
                    else
                    {
                        $thumb_image = 'application/layouts/scripts/'.$front_template['theme_folder'].'/images/mod_property_img/no_image.png';
                    }		
                }
                if($this->group_datas['file_thumb_width'] && ($this->group_datas['file_thumb_resize_func'] == 'resizeToWidth' || $this->group_datas['file_thumb_resize_func'] == 'resize'))
                { 
                    $width = 'width="'.$this->escape($this->group_datas['file_thumb_width']).'"'; 
                }
                else
                {
                    $width = '';
                } 
                if($this->group_datas['file_thumb_height'] && ($this->group_datas['file_thumb_resize_func'] == 'resizeToHeight' || $this->group_datas['file_thumb_resize_func'] == 'resize'))
                { 
                    $height = 'height="'.$this->escape($this->group_datas['file_thumb_height']).'"'; 
                } 
                else
                {
                    $height = '';
                }
				$featured_class = ($entry['featured'] == '1') ? 'products-featured' : '' ;
                ?>
                  <tr>
                    <td>
                    	<div class="products-list">
                       		<!-- list Header Start -->
                            <div class="list-header">
                            	<div class="header-row">
                                    <div class="header-left">
                                        <span class="title-small">
                                        <a href="<?php echo $this->url(array('module' => 'Property','controller' =>'frontend', 'action' => 'details','property_title' => $this->escape($entry['property_title']) ),'Property-details/:property_title',true); ?>" class="preview" title="<?php echo $this->escape($entry['property_name']); ?>" link=""><?php echo $this->escape(property_truncate($entry['property_name'], 0, 5)); ?></a></span><br />
                                        <span class="info"><?php if(!empty($entry['feature_room_no'])){ echo (int)$this->escape($entry['feature_room_no']).' '.$this->translator->translator('property_front_page_room'); } if(!empty($entry['feature_bedroom'])){ echo ', '.(int)$this->escape($entry['feature_bedroom']).' '.$this->translator->translator('property_front_page_property_bedroom_no'); } ?></span>
                                    </div>
                                
                                    <div class="header-middle">
                                        <span class="products-mark"><?php $type_infos = $business_type_db->getBusinessTypeInfo($entry['property_type']); echo $this->translator->translator('property_front_page_property_for'); ?></span>&nbsp;<span class="products-type"><?php echo $this->escape($type_infos['business_type']); ?></span>
                                    </div>
                                
                                    <div class="header-right">                                                
                                        <?php 
                                            if(!empty($this->group_datas['review_id'])){ 
                                            $review_no = $review_helper->getNumOfReviews($entry['id'], $this->escape($this->group_datas['review_id']));
                                        ?><span class="products-write-review"><a href="<?php echo $this->url( array('module' => 'Review','controller' => 'frontend', 'action'     => 'write', 'group_id' => $this->escape($this->group_datas['review_id']), Eicra_File_Constants::ITEM_ID => $entry['id'] ), 'Review-Write/:group_id/:item_id',    true); ?>"><?php echo $this->translator->translator('common_write_review'); ?></a></span> &nbsp; <span class="products-review-count"><a href="<?php echo $this->url(array('module' => 'Property','controller' =>'frontend', 'action' => 'details','property_title' => $this->escape($entry['property_title']),'tab' => 7 ),'Property-details/:property_title/:tab',true); ?>"><?php echo $this->translator->translator('common_review_no',htmlentities($review_no)); ?></a></span> <?php } ?>
                                    </div>
                           		</div>
                            </div>
                            <!-- list Header End -->
                            
                            <!-- list Body Start --> 
                            <div class="body-container <?php echo $featured_class; ?>">
                                 <div class="left-content">
                                 		<div class="img-wrapper">
                                        	<a href="<?php echo $this->url(array('module' => 'Property','controller' =>'frontend', 'action' => 'details','property_title' => $this->escape($entry['property_title']) ),'Property-details/:property_title',true); ?>" class="preview" link="<?php echo $thumb_image; ?>" width="350" title="<?php echo $this->escape($entry['property_name']); ?>"><img src="<?php echo $thumb_image; ?>" <?php echo $width; ?> <?php echo $height; ?> border="0" class="thumb" /></a>
                                       		<div class="photo-count-container">
                                                <div class="photo-count">
                                                    <a href="<?php echo $this->url(array('module' => 'Property','controller' =>'frontend', 'action' => 'details','property_title' => $this->escape($entry['property_title']),'tab' => 1 ),'Property-details/:property_title/:tab',true); ?>" title="<?php echo $this->translator->translator('property_front_page_click_view_photos'); ?>"><?php echo $this->translator->translator('property_front_page_property_photo_no', $property_image_no); ?></a>
                                                </div>
                                            </div>                                            
                                        </div>
                                        
                                        <h2>
                                        	<a href="<?php echo $this->url(array('module' => 'Property','controller' =>'frontend', 'action' => 'details','property_title' => $this->escape($entry['property_title']) ),'Property-details/:property_title',true); ?>" class="preview" title="<?php echo $this->escape($entry['property_name']); ?>" link=""><?php echo $this->escape(property_truncate($entry['property_name'], 0, 5)); ?></a>
                                        </h2>
                                        
                                        <div class="products-stars">
										<?php
                                            for($i = 1; $i < $maximum_stars_digit; $i++)
                                            {
                                                $property_stars = ($i <= $this->escape($entry['stars'])) ? "<img src='application/layouts/scripts/".$front_template['theme_folder']."/images/mod_property_img/star-active.png' border='0' />" : "<img src='application/layouts/scripts/".$front_template['theme_folder']."/images/mod_property_img/star-inactive.png' border='0'/>";
                                                echo $property_stars.'&nbsp;';
                                            }
                                        ?>
                                        </div>
                                        
                                        <div class="products-desc">
                                           	<p><?php echo $this->translator->translator('property_front_page_property_location'); ?></p> <?php $states = $state_db->getStateInfo($entry['state_id']); $areas = $area_db->getAreaInfo($entry['area_id']); echo $this->escape($areas['city']).', '.$this->escape($states['state_name']).', '.$this->escape($entry['post_code']).'.'; ?><br />
                                            <p><?php echo $this->translator->translator('property_front_page_property_country'); ?></p> <?php $countries = $country_db->getCountryName($entry['country_id']); echo $this->escape($countries['value']); ?><br />

                                            <p><?php echo $this->translator->translator('property_front_page_property_desc'); ?></p>
                                            <span class="jTruncate"><?php echo $this->escape(strip_tags($entry['property_desc'])); ?></span>
                                        </div>
                                 </div>
                                 
                                 <div class="right-content">
                                 	<span class="products-price"><?php  echo $this->translator->translator('property_front_page_price').$currency->getSymbol().' '.$this->price($this->escape($entry['property_price']));  ?></span>
                                    <ul class="products-options">
                                    	<?php
										if(!empty($property_type_arr[0]) && in_array($entry['property_type'], $property_type_arr))
										  {
										?>
										<li class="availability"><a href="<?php echo $this->url(array('module' => 'Property','controller' =>'frontend', 'action' => 'details','property_title' => $this->escape($entry['property_title']),'tab' => 4 ),'Property-details/:property_title/:tab',true); ?>"><?php echo $this->translator->translator('property_front_page_label_check-availability'); ?></a></li>
										<?php
										  }
										  if(!empty($entry['feature_bathroom']))
										  {
										?>	
                                        <li class="bathroom"><?php  echo $this->translator->translator('maid_age').' '.(int)$this->escape($entry['feature_bathroom']).' '.$this->translator->translator('property_front_page_bathroom'); ?></li>
                                       	<?php
										  }
										?>
                                        
                                        <li class="kitchen"><?php echo ($entry['feature_kitchen']) ? $this->translator->translator('property_front_page_property_has_kitchen') : $this->translator->translator('property_front_page_property_no_kitchen') ; ?></li>
                                        
                                        <li class="garden"><?php echo ($entry['feature_garden']) ? $this->translator->translator('property_front_page_property_has_garden') : $this->translator->translator('property_front_page_property_no_garden') ; ?></li>
 
                                        <li class="garage"><?php echo ($entry['feature_garage']) ? $this->translator->translator('property_front_page_property_has_garage') : $this->translator->translator('property_front_page_property_no_garage') ; ?></li>
                                    </ul>
                                    
                                    <div class="products-vote">
                                        <p><?php echo $this->translator->translator('property_front_page_label_voting'); ?></p>
                                        <span><?php  $vote->showButton($entry['id'] , $this->escape($entry['property_name'])); ?></span>
                                    </div>                
                                 </div>    
                            </div>
                            <!-- list Body End -->
                            
                            <!-- list footer start -->
                            <div class="list-footer">
                                <div class="footer-left">
                                    
                                    <a href="<?php echo $this->url(array('module' => 'Property','controller' =>'frontend', 'action' => 'details','property_title' => $this->escape($entry['property_title']),'tab' => 2 ),'Property-details/:property_title/:tab',true); ?>"><?php echo $this->translator->translator('property_front_page_property_fpan'); ?></a>  | 
                                    <a href="<?php echo $this->url(array('module' => 'Property','controller' =>'frontend', 'action' => 'details','property_title' => $this->escape($entry['property_title']),'tab' => 3 ),'Property-details/:property_title/:tab',true); ?>"><?php echo ucfirst(strtolower($this->translator->translator('property_front_page_property_map'))); ?></a>  | 
                                    <a href="<?php echo $this->url(array('module' => 'Property','controller' =>'frontend', 'action' => 'details','property_title' => $this->escape($entry['property_title']),'tab' => 1 ),'Property-details/:property_title/:tab',true); ?>"><?php echo $this->translator->translator('property_front_page_property_photo'); ?></a> | 
                                    <a href="<?php echo $this->url(array('module' => 'Property','controller' =>'emails', 'action' => 'friend','property_title' => $this->escape($entry['property_title']), 'form_id' => $this->translator->translator('email_to_friend_form_id') ),'Email-To-Friend/:property_title/:form_id',true); ?>"><?php echo $this->translator->translator('property_front_page_property_email_friend'); ?></a>
                                </div>
                            
                                <div class="footer-right">
                                	<?php if($global_conf['payment_system'] == 'On'){ ?>
                                    <span class="products-book-btn"><?php  if(!empty($property_type_arr[0]) && in_array($entry['property_type'], $property_type_arr)){ ?><a href="<?php echo $this->url(array('module' => 'Property','controller' =>'book', 'action' => 'booking','property_title' => $this->escape($entry['property_title']) ),'Book-Property/:property_title',true); ?>"><?php echo $this->translator->translator('property_front_page_property_book'); ?></a><?php } ?></span>
                                    <?php } ?>
                                    <span class="products-details-btn"><a href="<?php echo $this->url(array('module' => 'Property','controller' =>'frontend', 'action' => 'details','property_title' => $this->escape($entry['property_title']) ),'Property-details/:property_title',true); ?>"><?php echo $this->translator->translator('property_front_page_property_more'); ?></a></span>
                                </div>
                            </div>
                            <!-- list footer end -->
                    	</div>
                    </td>
                  </tr>
          <?php
            }
          ?>
        </tbody>
    </table>

	<!-- Pagination Section -->
  	<div id="bottomPagination">
		<?php
			if(!empty($this->view_datas))
			{
				echo $this->paginationControl($this->view_datas, 'Sliding', 'regionlist/view-city-pagination-flickr.phtml'); 	 
			}
		?>
	</div>
</div>
<?php endif; ?>	